home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / cmdlg7.zip / FNAMEDLG.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-10  |  5KB  |  189 lines

  1. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  2. {   \\\                                    }
  3. {  -(j)-                                   }
  4. {    /juanca                               }
  5. {    ~                                     }
  6. {   ⌐ ACASA 1989-1992, All rights reserved }
  7. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  8.  
  9. UNIT FNAMEDLG;
  10. {$C MOVEABLE DEMANDLOAD DISCARDABLE}
  11. INTERFACE
  12.   USES
  13.     WINTYPES,
  14.     OBJECTS,
  15.     OWINDOWS,
  16.     ODIALOGS,
  17.     COMMDLG,
  18.     COMONDLG;
  19.  
  20.  
  21.   TYPE
  22.     pFileNameDlg = ^tFileNameDlg;
  23.     tFileNameDlg = OBJECT ( tCommonDlg )
  24.  
  25.       openFileName :tOpenFileName;
  26.       filePath,
  27.       fileName     :tCString;
  28.       toOpen       :Boolean; 
  29.  
  30.  
  31.       CONSTRUCTOR
  32.       init(iparent:PWindowsObject; name :PChar; iToOpen :Boolean);
  33.  
  34.       FUNCTION
  35.       defSpec :PChar;
  36.         virtual;
  37.  
  38.       FUNCTION
  39.       defExt :PChar;
  40.         virtual;
  41.  
  42.       FUNCTION
  43.       defSpecPos:Byte;
  44.         virtual;
  45.  
  46.       FUNCTION
  47.       openFlags :Longint;
  48.         virtual;
  49.  
  50.       FUNCTION
  51.       doExec:Boolean;
  52.         virtual;
  53.  
  54.       FUNCTION
  55.       execute:Integer;
  56.         virtual;
  57.  
  58.     END;
  59.  
  60. {****************************************************************}
  61. IMPLEMENTATION
  62.  
  63.  
  64.       CONSTRUCTOR
  65.       tFileNameDlg.
  66.       {}
  67.       init(iparent:PWindowsObject; name :PChar; iToOpen :Boolean);
  68.         begin
  69.           inherited init(iparent, name);
  70.           toOpen := iToOpen;
  71.           fillChar(filePath, sizeOf(filePath), #0);
  72.           fillChar(fileName, sizeOf(fileName), #0);
  73.           FillChar(openFileName, SizeOf(TOpenFileName), #0);
  74.         end;
  75.  
  76.       FUNCTION
  77.       tFileNameDlg.
  78.       {}
  79.       defSpec :PChar;
  80.         begin
  81.           defSpec := 'All Files (*.*)'#0'*.*'#0'Override this(!@$%.#%!)'#0'!@$%.#%!'#0'TextFiles (*.txt)'#0'*.txt'#0
  82.         end;
  83.  
  84.       FUNCTION
  85.       tFileNameDlg.
  86.       {}
  87.       defSpecPos:Byte;
  88.         begin
  89.           defSpecPos := 1 {of the specifiers given ind 'defSpec', which is default, 1 is first}
  90.         end;
  91.  
  92.       FUNCTION
  93.       tFileNameDlg.
  94.       {}
  95.       defExt :PChar;
  96.         begin
  97.           defExt := 'txt'  {override this to be the your default extension
  98.                             extension SHOULD NOT CONTAIN A PERIOD '.'}
  99.         end;
  100.  
  101.       FUNCTION
  102.       tFileNameDlg.
  103.       {}
  104.       openFlags:Longint;
  105.         begin
  106.             { this can be set to any OFN_ flags, but don't use the template related ones}
  107.           if toOpen
  108.           then
  109.             openFlags := OFN_PATHMUSTEXIST or OFN_HIDEREADONLY
  110.           else
  111.             openFlags := OFN_PATHMUSTEXIST or OFN_HIDEREADONLY
  112.                                            or OFN_NOREADONLYRETURN
  113.         end;
  114.  
  115.       FUNCTION
  116.       tFileNameDlg.
  117.       {}
  118.       doExec:Boolean;
  119.         begin
  120.           if toOpen
  121.           then
  122.             doExec := getOpenFileName(openFileName)
  123.           else
  124.             doExec := getSaveFileName(openFileName)
  125.         end;
  126.  
  127.  
  128.       FUNCTION
  129.       tFileNameDlg.
  130.       {}
  131.       execute:Integer;
  132.         var
  133.           result :Integer;
  134.           oldKBHandler :pWindowsObject;
  135.         begin
  136.           with openFileName do
  137.           begin
  138.             lStructSize   := sizeof(openFileName);
  139.             hInstance     := SYSTEM.HInstance;
  140.             if parent <> nil
  141.             then
  142.               hwndOwner   := parent^.hWindow
  143.             else
  144.               hwndOwner   := 0;
  145.             lpstrTitle    := dlgTitle;
  146.             lpTemplateName:= attr.Name;
  147.             lpstrFilter   := defSpec;
  148.             nFilterIndex  := defSpecPos;       {Index into Filter String in lpstrFilter}
  149.             lpstrDefExt   := defExt;
  150.             lpstrFile     := filePath;
  151.             lpstrFileTitle:= fileName;
  152.             flags         := openFlags;
  153.             if (lpTemplateName <> nil)
  154.             then
  155.               flags := flags or OFN_ENABLETEMPLATE
  156.             else
  157.               lpTemplateName := nil;
  158.             nMaxFile      := sizeOf(filePath);
  159.             nMaxFileTitle := sizeOf(fileName);
  160.  
  161.             lCustData    := Longint(@Self);  {this does nothing, but could be usefull}
  162.  
  163.             move(Self.instance, lpfnHook, sizeOf(lpfnHook)); {this does the trick!}
  164.  
  165.             flags := flags or OFN_ENABLEHOOK 
  166.           end;
  167.  
  168.           oldKbHandler := Application^.KBHandlerWnd;
  169.           isModal      := TRUE;  { this is very important, object gets freed twice otherwise !}
  170.           if doExec
  171.           then
  172.             execute := id_Ok
  173.           else begin
  174.             result := commDlgExtendedError;
  175.             if result = 0
  176.             then
  177.               execute := id_Cancel
  178.             else begin
  179.               execute := -result;
  180.               status  := em_InvalidWindow
  181.             end;
  182.           end;
  183.           hwindow := 0;
  184.           isModal := FALSE;
  185.           Application^.KBHandlerWnd := OldKbHandler;
  186.         end;
  187.  
  188.  
  189. END.